package com.ky.pro.java.concurrency;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import static com.ky.pro.java.concurrency.algo.FiboUtil.fibo;

/**
 * @ClassName CallableMain
 * @Description 使用线程池+Callable+Future实现
 * @Date 2021/11/23 22:19
 * @Author kevin
 **/
public class CallableMain {

    public static void main(String[] args) throws InterruptedException, ExecutionException {

        long start = System.currentTimeMillis();

        // 在这里创建一个线程或线程池，
        // 异步执行 下面方法

        ExecutorService executorService = Executors.newFixedThreadPool(4);
        Future<Integer> future = executorService.submit(() -> fibo(36));

        // 确保  拿到result 并输出
        System.out.println("异步计算结果为：" + future.get());

        System.out.println("使用时间：" + (System.currentTimeMillis() - start) + " ms");

        // 然后退出main线程

        executorService.shutdown();
    }

}
